package com._4pd.demo.formal.entity;


import io.fabric8.kubernetes.client.dsl.base.ResourceDefinitionContext;
import lombok.Data;

import java.util.Map;

@Data
public class K8sCommonResource {
    private String apiVersion;
    private String kind;
    private Map<String,Object> metadata;
    private Map<String,Object> spec;

    public ResourceDefinitionContext buildResourceDefinitionContext(){
        ResourceDefinitionContext.Builder builder = new ResourceDefinitionContext.Builder();
        if (kind != null) {
            builder.withKind("Workflow");
        }
        if (apiVersion != null) {
            String[] split = apiVersion.split("/");
            builder.withGroup(split[0]);
            builder.withVersion(split[1]);
        }
        builder.withNamespaced(true);
        return builder.build();
    }
}
